package net.tv90.weatherserveradmin.dao;

import net.tv90.weatherserveradmin.model.domain.WeatherStationData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface WeatherStationDataRepository extends JpaRepository<WeatherStationData, Long> {

    @Query("SELECT MAX(w.datetime) FROM WeatherStationData w WHERE w.stationId IN :stationIDs")
    String findLatestDate(@Param("stationIDs") String stationIDs);

    // Custom query to fetch weather data based on stationID and datetime range
    @Query("SELECT w FROM WeatherStationData w WHERE w.stationId IN :stationIDs " +
            "AND w.datetime BETWEEN :startDate AND :endDate " +
            "ORDER BY w.datetime DESC")
    List<WeatherStationData> findWeatherDataByDateRange(
            @Param("stationIDs") String stationIDs,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate);
}